/***************************************************************************/
/*                       Configure IR Transceiver                          */
/***************************************************************************/

Method A. -- Call the functions in "IRLib.DLL".

   1. Open COM port
      C/C++ : call "OpenIrCom"
      VB    : call "vbOpenIrCom"

   2. Read / Write data
      C/C++ : call "ReadIrCom" / "WriteIrCom" or just call Windows APIs.
      VB    : call "vbReadIrCom" / "WriteIrCom"

   3. Close COM port
      C/C++ : call "CloseIrCom" or call Windows API - "CloseHandle()"
      VB    : call "CloseIrCom"

   For details of the library, please refer to "IRLib.H".


Method B. -- Programming IR Transceiver

   There are three steps to program the IR Transceiver
   1. Get power from the DTR.
   2. Detect the IR module's current baud rate.
   3. Set new baud rate.

   To detect the baud rate and then set new baud rate for the IR module, 
   you need to set control characters to its registers. Note there are five
   registers, but only register 1, 3 and 5 are useful. The format of a
   control character is as follows:
   
   The higher 4 bits are interpreted as address field and the lower 4 bits
   are interpreted as data field (command).

   Address : b7, b6, b5, b4 (the high bits)
   Data    : b3, b2, b1, b0 (the low bits)

   The Address and Data (command) for each Register are as follows:
      
      Address(b7,b6,b5,b4)       Register

              0000           Control register 1
              0010           LED current register (don't care)
              0011           Baud rate register
              0100           Mode register (don't care)
              0101           Control register 2

   1. Data of Control register 1 (b3,b2,b1,b0)
   
      b3 : ECHO  0  Echo control characters ................... No
                 1  Echo control characters ................... Yes
      b2 : ECAN  0  Cancel the receipt of data transmitted
                    (self-emitted) ............................ No
                 1  Cancel the receipt of data transmitted
                    (self-emitted) ............................ Yes
      b1 : RXEN  0  Receiver .................................. Disabled
                 1  Receiver .................................. Enabled
      b0 : TXEN  0  Transmiter ................................ Disabled
                 1  Transmiter ................................ Enabled

      reset : 0000

   2. LED current register (don't care)

   3. Baud rate register 

      Data (command)         Meaning

              0000           2.4 Kbps
              0001           4.8 Kbps
              0010           9.6 Kbps
              0011          19.2 Kbps
              0100          38.4 Kbps
              0101          57.6 Kbps
              0110         115.2 Kbps

      reset : 0010

   4. Mode register (don't care)

   5. Control register 2

      Data (command)         Meaning

              0000     Do not load new baud rate count value
              0001     Load new baud rate count value

      reset : 0000

   /***********************************************/
   /*            Programming sequences            */
   /***********************************************/

   1. Get power from DTR

      Enable RTS (low!)
      Enable DTR (low!)

   2. Check current baud rate of the IR Transceiver

      Disable RTS (high!)
      Set to a testing baud rate
      Send 0x0f to the IR (set Control register 1) and waiting for echo.
      If echo value is 0x0f, then the baud rate is correct.
      Enable RTS (low!)

      If baud rate is incorrect, repeat above procedures with another baud rate.

   3. Use current baud rate of the IR Transceiver to change its settings.

      Disable RTS (high!)
      Send 0x07 to IR (set Control register 1, disable echo).
      Send control character with new baud rate (eg. 0x34 for 38.4K) to IR.
      Send 0x51 to IR so that it will load the new baud rate.
      Enable RTS (low!)

   4. Done. You can start to send data to the IR port.
